package com.webservice.xmloper.commonDataManager;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class ServiceContentConvertor implements Converter{

	public void marshal(Object source, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		ServiceContent serviceContent = null;
		if(source != null ){
			serviceContent = (ServiceContent) source;
		}
		if(serviceContent != null && serviceContent.getServiceContent() != null){
			writer.setValue(serviceContent.getServiceContent().toString());
		}else{
			writer.setValue("");
		}
	}

	public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		ServiceContent serviceContent = new ServiceContent();
		try{
			Integer readerInt = Integer.valueOf(reader.getValue());
			serviceContent.setServiceContent(readerInt);
		}catch(Exception e){
			e.printStackTrace();
			serviceContent.setServiceContent(null);
		}
        return serviceContent;
	}

	public boolean canConvert(Class type) {
		 return type.equals(ServiceContent.class);
	}


}
